﻿Imports System.IO
Imports System.Windows
Public Class frmMain
    Dim moveTimer As New Timer
    Dim mykey As New Microsoft.VisualBasic.Devices.Keyboard

    'AddHandler moveTimer.Tick, AddressOf Me.resizeForm
    'moveTimer.Start()

    'Private Sub resizeForm()
    '    Dim t As Int32 = 1
    '    Dim hLimit As Integer = 240
    '    If Button2.Tag = "down" Then t = -1 : hLimit = 120

    '    Dim counter As Int32 = 0
    '    While counter < hLimit
    '        counter += t
    '        Me.Height = hLimit + counter
    '    End While
    '    moveTimer.Stop()
    'End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then MsgBox("WoW Launcher already started!") : End 'MsgBox(setLangValue(LNG_MSG_1)) '2 лаунчера одновременно не могут быть запущены
        If File.Exists(RLPath) = False Then MsgBox(String.Format("{0}\realmlist.wtf not found!", Application.StartupPath)) : End
        If File.Exists(WOWPath) = False Then MsgBox(String.Format("{0}\WoW.exe not found!", Application.StartupPath)) : End

        Me.Icon = My.Resources.wowInverted

        realmlist = loadRealmList()
        Dim lvi As New ListViewItem
        listRealms.DataSource = realmlist
        listRealms.AutoCompleteSource = AutoCompleteSource.ListItems
        listRealms.Text = currentRealm
    End Sub

    Private Sub listRealms_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles listRealms.TextChanged
        If listRealms.Text.Trim.Length > 2 Then
            btnGO.Enabled = True
        Else
            btnGO.Enabled = False
        End If
    End Sub

    Private Sub btnGO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGO.Click
        Dim counter As Integer = 0
        Dim currentRealmExists = False 'содержание текущего реалма в списке реалмов
        currentRealm = listRealms.Text 'set current realm

        If searchInArray(realmlist, currentRealm.Trim) = False Then 'добавить сервер, если его нет в списке
            Array.Resize(realmlist, realmlist.Length + 1)
            realmlist(realmlist.Length - 1) = currentRealm 'последнему элементу присвоить текущий сервер
            listRealms.DataSource = realmlist
            listRealms.Text = currentRealm
        End If

        Dim streamArray(realmlist.Length - 1) As String

        'all realms to array
        For Each realm In realmlist
            If realm <> Nothing Then
                streamArray(counter) = String.Format("set realmlist {0}", realm)
                If realm <> currentRealm Then streamArray(counter) = String.Format(";{0}", streamArray(counter))

                counter += 1
            End If
        Next

        saveToFile(streamArray, RLPath)
        Process.Start(WOWPath)

    End Sub

    Private Sub lblMailToAuthor_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lblMailToAuthor.LinkClicked
        Process.Start(lblMailToAuthor.Text)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim data As Object
        Dim cliptext As String
        If mykey.CtrlKeyDown = True Or mykey.AltKeyDown = True Then
            Me.Text = mykey.GetHashCode

            'Clipboard.Clear()
            'If mykey.AltKeyDown = True Then
            'Clipboard.SetData(DataFormats.Text, "helo")
            'ElseIf mykey.CtrlKeyDown = True Then
            'Clipboard.SetData(DataFormats.Text, "heloawg")
            'End If
            cliptext = Clipboard.GetData(DataFormats.Text)
            Clipboard.Clear()
            SendKeys.SendWait(cliptext) 'ctrl+a & {ctrl}+del & ctrl+v
        End If
    End Sub
End Class
